﻿@{
    Layout = "../Shared/_Default.cshtml";
    ViewBag.PageTitle = T(Res.Name("Title"), JDM.String(Model.Topic.Title));
    ViewBag.PageHistory = String.IsNullOrWhiteSpace(Request.QueryParam("searchTerm")) && 
        String.IsNullOrWhiteSpace(Request.QueryParam("page"));
}

@section Breadcrumb
{
    @{
        Html.RenderAction(Loc.Act("_Breadcrumb").Ctrl("Forum").Set(new
        {
            id = JDM.Int32(Model.Forum.EntityID),
            full = true
        }).Localized());
    }
}
@section Toolbar
{
    <span>@T(Res.Name("Stat"), JDM.Int32(Model.Topic.PostCount))</span>
    @if(Model.UserCanWrite)
    {
        <span class="separator">&middot;</span>
        <a href="@Url.Action(Loc.Act("Create").Ctrl("ForumPost").Area("Wizard").Set(new
        {
            topicID = JDM.Int32(Model.Topic.EntityID)
        }).Localized())">@T(Res.Name("Post"))</a>
    }
    @if(Model.UserCanModerate || (Svc.IsAuthenticated && JDM.Int32(Model.Topic.Member.EntityID) == JDM.Int32(Svc.ForumMember.EntityID)))
    {
        <span class="separator">&middot;</span>
        <a href="@Url.Action(Loc.Act("Edit").Ctrl("ForumTopic").Area("Wizard").Set(new
        {
            id = JDM.Int32(Model.Topic.EntityID)
        }).Localized())">@T(Res.In("Common").Of("Act").Name("Edit"))</a>
    }
}
<div class="box">
    <section>
        <div class="unit forum-topic forum-topic-entry">
            <header>
                <nav>
                    @{
                        Html.RenderPartial("_Avatar", (object)Model.Topic.Member);
                    }
                    <span class="separator">&nbsp;</span>
                    <span>@Svc.DateTimeRel((DateTime)JDM.DateTime(Model.Topic.CreatedOn))</span>
                    <a href="@Url.Action(Loc.Act("Show").Ctrl("Account").NoArea().Set(new
                    {
                        id = JDM.Int32(Model.Topic.Member.Account.EntityID)
                    }).Localized())">@T(Res.In("Common").Of("Expr").Name("By"), JDM.String(Model.Topic.Member.Account.Username))</a>
                </nav>
            </header>
            <section>
            @{
                Html.RenderPartial("_Description", (object)Model.Topic);
                Html.RenderPartial("_Signature", (object)Model.Topic.Member);
            }
            </section>
        </div>
        @if(!Model.UserCanWrite)
        {
            <div class="hint">
                <p>@T(Res.Name("ReadOnly"))</p>
            </div>
        }
    </section>
    <section>
    @{
        Html.RenderPartial("_Posts");
        Html.RenderPartial("_Pager", new ViewDataDictionary 
        { 
            { "PageNum", 6 },
            { "PageCount",  Math.Ceiling(JDM.Double(Model.Posts.TotalCount) / Model.CountPerPage) }, 
            { "PageIndex", Request.QueryParam("page", 0) },
            { "PageParam", "page" },
            { "PageSize", Model.CountPerPage },
            { "PageRoute", Loc.Act("Show").Use("id", "searchTerm").Localized() } 
        });
        Html.RenderPartial("_Search", (object)Model.Topic);
    }
    </section>
</div>
